1. Field of the Invention
The present invention relates to computer graphics. More particularly, it relates to implementing derivative operators with graphics hardware.
2. Related Art
Computer graphics systems are used to render all kinds of objects for display. In general, it is important that objects rendered for display appear as realistic to a viewer as possible. This is particularly the case, for example, in computer graphics imagery (CGI) for use in motion pictures and animation. In many applications, it is also important that the computer graphics system used to render objects for display operate at an interactive rate. As would be known to a person skilled in the relevant art, programmable shading can be used to render objects that appear very realistic to a viewer, but programmable shading cannot be implemented at an interactive rate in most, if not all, available computer graphics systems.
Programmable shading involves the use of a special programming language known in the relevant art as a shading language. A shading language is used to specify the appearance and surface characteristics of objects in an image or a scene. See Pat Hanrahan""s and Jim Lawson""s xe2x80x9cA language for Shading and Lighting Calculations,xe2x80x9d in Computer Graphics (SIGGRAPH ""90 Proceedings) Vol. 24, pp. 289-94, which is herein incorporated by reference in its entirety, for a description of a shading language. A typical shading language can simulate a wide variety of appearances including, for example, wood, metal, plastic, fabric, glass, hair, skin, et cetera. A shading language can also be used to describe the emission characteristics of light sources in a scene, the color and reflective properties of each object in a scene, and the transmittance properties of atmospheric media. In many CGI applications, the appearance and surface characteristics of every object in a scene are described using a shading language. As would be known to a person skilled in the relevant art, programmable shading plays an important role in the creation of special effects for movies and television. Programmable shading also plays an important role in other applications as well, for example, in engineering and scientific applications for visualization of data.
A key feature of most shading languages is the ability to implement derivative operators. A derivative operator is a function that returns a derivative value. Derivative operators are used in computer graphics. For example, derivative operators are used for determining surface normals, for determining noise frequency limits, and for antialiasing. Implementing derivative operators can be a significant task in computer graphics. Calculating derivatives can consume a significant amount of the total processing time needed to render an image. Using a shading language to implement derivative operators, however, significantly simplifies the task.
A typical application program accesses shading language procedures, including derivative operators, through a programmable interface extension of a graphics application programming interface (graphics API). As would be known to a person skilled in the relevant art, a shading language is basically a library of procedures, known in the relevant art as shaders, that can be called during the rendering of an image. A shading language procedure can have very general programing constructs such as loops, conditional statements, and functions. In some examples, shading language source files (i.e., procedures) are compiled to produce object files. When a scene description using a shading language is being rendered, an object file corresponding to a shader must be retrieved from a library and loaded into the memory of the computer graphics system being used to render the scene. The object file must then be executed by the graphics system""s general purpose processor in order to produce the desired effects in the rendered scene.
The known methods used to implement shading language procedures, including derivative operators, place a significant burden on the graphics hardware and driver software of computer graphics systems. Graphics hardware is generally designed to support a parametric appearance model. For example, Phong lighting is evaluated per vertex with one or more texture maps applied after Gouraud interpolation of the lighting results. Graphics hardware is not designed to support the general programming constructs of a shading language. Therefore, known shading language procedures such as, for example, shading language derivative operators are translated into a general purpose programing language and compiled to run on a general purpose processor. Because general purpose processors are not designed to process millions of pixels each second, as are special purpose graphics processors and graphics hardware, the known methods used to implement shading language procedures cannot be implemented at an interactive rate on most, if not all, available computer graphic systems.
What is needed is a method, system, and computer program product for implementing derivative operators at an interactive rate in computer graphics systems. In particular, what is needed is a method, system, and computer program product for implementing derivative operators with graphics hardware.
The present invention provides a method, system, and computer program product for implementing derivative operators at an interactive rate in computer graphics systems. In an embodiment, a data structure representing the operation of one or more computer program statements is received by a compiler and transformed into a tree data structure. Nodes of the tree data structure that determine derivative information are marked. A transform rule is applied to the marked nodes to transform the tree data structure into a data structure that can be implemented with graphics hardware interface program statements. In one embodiment of the invention, the compiler transforms shading language statements into graphics application programming interface statements that can be implemented with multiple passes through a graphics pipeline. It is a feature of the present invention that it can be implemented on a wide range of computer graphics systems.